#include "wx/wxprec.h"
#include "wx/artprov.h"

class wxDefaultArtProvider : public wxArtProvider {
  protected:
    virtual wxBitmap CreateBitmap( const wxArtID& id, const wxArtClient& client, const wxSize& size );
};

#define ART(artId, xpmRc) \
  if ( id == artId ) return wxBitmap(xpmRc##_xpm);

#if defined(__WXUNIVERSAL__)
#define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
#elif defined(__WXGTK__) || defined(__WXMOTIF__)
#define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
#else
#define CREATE_STD_ICON(iconId, xpmRc) \
  { \
    wxIcon icon(_T(iconId)); \
    wxBitmap bmp; \
    bmp.CopyFromIcon(icon); \
    return bmp; \
  }
#endif

#define ART_MSGBOX(artId, iconId, xpmRc) \
  if ( id == artId ) \
  { \
    CREATE_STD_ICON(#iconId, xpmRc) \
  }


void wxArtProvider::InitStdProvider() {
  wxArtProvider::Push( new wxDefaultArtProvider );
}

#if !defined(__WXGTK20__) || defined(__WXUNIVERSAL__)
void wxArtProvider::InitNativeProvider() {
}
#endif

#include "info.xpm"
#include "error.xpm"
#include "warning.xpm"
#include "question.xpm"
#include "htmsidep.xpm"
#include "htmoptns.xpm"
#include "htmbook.xpm"
#include "htmfoldr.xpm"
#include "htmpage.xpm"
#include "missimg.xpm"
#include "addbookm.xpm"
#include "delbookm.xpm"
#include "back.xpm"
#include "forward.xpm"
#include "up.xpm"
#include "down.xpm"
#include "toparent.xpm"
#include "fileopen.xpm"
#include "print.xpm"
#include "helpicon.xpm"
#include "tipicon.xpm"
#include "home.xpm"
#include "repview.xpm"
#include "listview.xpm"
#include "new_dir.xpm"
#include "harddisk.xpm"
#include "cdrom.xpm"
#include "floppy.xpm"
#include "removable.xpm"
#include "folder.xpm"
#include "folder_open.xpm"
#include "dir_up.xpm"
#include "exefile.xpm"
#include "deffile.xpm"
#include "tick.xpm"
#include "cross.xpm"
#include "filesave.xpm"
#include "filesaveas.xpm"
#include "copy.xpm"
#include "cut.xpm"
#include "paste.xpm"
#include "delete.xpm"
#include "new.xpm"
#include "undo.xpm"
#include "redo.xpm"
#include "quit.xpm"
#include "find.xpm"
#include "findrepl.xpm"

wxBitmap wxDefaultArtProvider_CreateBitmap( const wxArtID& id ) {
  ART_MSGBOX( wxART_ERROR, wxICON_ERROR, error )
  ART_MSGBOX( wxART_INFORMATION, wxICON_INFORMATION, info )
  ART_MSGBOX( wxART_WARNING, wxICON_WARNING, warning )
  ART_MSGBOX( wxART_QUESTION, wxICON_QUESTION, question )
  #if wxUSE_HTML
  ART( wxART_HELP_SIDE_PANEL, htmsidep )
  ART( wxART_HELP_SETTINGS, htmoptns )
  ART( wxART_HELP_BOOK, htmbook )
  ART( wxART_HELP_FOLDER, htmfoldr )
  ART( wxART_HELP_PAGE, htmpage )
  #endif
  ART( wxART_MISSING_IMAGE, missimg )
  ART( wxART_ADD_BOOKMARK, addbookm )
  ART( wxART_DEL_BOOKMARK, delbookm )
  ART( wxART_GO_BACK, back )
  ART( wxART_GO_FORWARD, forward )
  ART( wxART_GO_UP, up )
  ART( wxART_GO_DOWN, down )
  ART( wxART_GO_TO_PARENT, toparent )
  ART( wxART_GO_HOME, home )
  ART( wxART_FILE_OPEN, fileopen )
  ART( wxART_PRINT, print )
  ART( wxART_HELP, helpicon )
  ART( wxART_TIP, tipicon )
  ART( wxART_REPORT_VIEW, repview )
  ART( wxART_LIST_VIEW, listview )
  ART( wxART_NEW_DIR, new_dir )
  ART( wxART_HARDDISK, harddisk )
  ART( wxART_FLOPPY, floppy )
  ART( wxART_CDROM, cdrom )
  ART( wxART_REMOVABLE, removable )
  ART( wxART_FOLDER, folder )
  ART( wxART_FOLDER_OPEN, folder_open )
  ART( wxART_GO_DIR_UP, dir_up )
  ART( wxART_EXECUTABLE_FILE, exefile )
  ART( wxART_NORMAL_FILE, deffile )
  ART( wxART_TICK_MARK, tick )
  ART( wxART_CROSS_MARK, cross )
  ART( wxART_FILE_SAVE, filesave )
  ART( wxART_FILE_SAVE_AS, filesaveas )
  ART( wxART_COPY, copy )
  ART( wxART_CUT, cut )
  ART( wxART_PASTE, paste )
  ART( wxART_DELETE, delete )
  ART( wxART_UNDO, undo )
  ART( wxART_REDO, redo )
  ART( wxART_QUIT, quit )
  ART( wxART_FIND, find )
  ART( wxART_FIND_AND_REPLACE, findrepl )
  ART( wxART_NEW, new )
  return wxNullBitmap;
}

wxBitmap wxDefaultArtProvider::CreateBitmap( const wxArtID& id, const wxArtClient& client, const wxSize& reqSize ) {
  wxBitmap bmp = wxDefaultArtProvider_CreateBitmap( id );
  #if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
  if( bmp.Ok() ) {
    if( reqSize == wxDefaultSize ) {
      wxSize bestSize = GetSizeHint( client );
      if( bestSize != wxDefaultSize ) {
        int bmp_w = bmp.GetWidth();
        int bmp_h = bmp.GetHeight();
        if( ( bmp_h < bestSize.x ) && ( bmp_w < bestSize.y ) ) {
          wxPoint offset( ( bestSize.x - bmp_w ) / 2, ( bestSize.y - bmp_h ) / 2 );
          wxImage img = bmp.ConvertToImage();
          img.Resize( bestSize, offset );
          bmp = wxBitmap( img );
        } else {
          wxImage img = bmp.ConvertToImage();
          bmp = wxBitmap( img.Scale( bestSize.x, bestSize.y, wxIMAGE_QUALITY_HIGH ) );
        }
      }
    }
  }
  #else
  wxUnusedVar( client );
  wxUnusedVar( reqSize );
  #endif
  return bmp;
}
